package com.grq.mis.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.grq.mis.entity.LoginRecord;
import com.grq.mis.service.LoginRecordService;
import com.grq.mis.entity.LoginRecord;
import org.beetl.sql.core.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/loginRecord")
public class LoginRecordController extends BaseController {

    @Autowired
    private LoginRecordService loginRecordService;

    @SaCheckPermission("loginRecord:list")
    @GetMapping("/page")
    public String page(
            Model model,
            @RequestParam(defaultValue = "1") long page,
            @RequestParam(defaultValue = "20") int size,
            String key
    ) {

        // 带入参数
        Map<String, Object> paras = new HashMap<>();
        if (!StringUtils.isEmpty(key)) {
            paras.put("key", "%" + key.trim() + "%");
        }

        PageResult<LoginRecord> result = loginRecordService.page("loginRecord.page", paras, page, size);
        model.addAttribute("data", result);

        model.addAttribute("key", key);

        return "loginRecord/page.html";
    }

}
